package com.sg.business.taskforms.projectchange;

import org.jbpm.task.Task;

import com.mobnut.db.model.PrimaryObject;
import com.sg.bpm.workflow.taskform.ITaskFormInputHandler;
import com.sg.bpm.workflow.taskform.TaskFormConfig;
import com.sg.business.model.Project;
import com.sg.business.model.TaskForm;
import com.sg.business.model.Work;
import com.sg.widgets.MessageUtil;

public class ProjectChangeLaunchInputHandler implements ITaskFormInputHandler {

	@Override
	public PrimaryObject getTaskFormInputData(PrimaryObject taskFormData,
			TaskFormConfig taskFormConfig, Task task) {
		if (taskFormData instanceof TaskForm) {
			TaskForm taskForm = (TaskForm) taskFormData;
			try {
				Work work = taskForm.getWork();
				if (work == null) {
					return null;
				}
				Project project = work.getProject();
				if (project == null) {
					return null;
				}
				taskForm.setValue("prj_charger", project.getChargerId());
			} catch (Exception e) {
				MessageUtil.showToast(e);
			}
			return taskForm;
		}
		return null;
	}

}
